import { Injectable } from '@angular/core';
import {MsgResult} from '../../../models/msg-result';
import {Observable} from 'rxjs/Rx';
import {RequestUtil} from '../../../util/request-util';
import {FormUtil} from '../../../util/form-util';
import {SiteV2API} from '../site-v2-constants';

@Injectable()
export class SiteCategorysService {

  constructor(
    private formUtil: FormUtil,
    private requestUtil: RequestUtil
  ) { }
  /**
   * 通过ID获取站点类型
   * @param id :站点类型
   * @returns {Observable<MsgResult>|any}
   */
  getSiteCateById(id): Observable<MsgResult> {
    return this.requestUtil.get(SiteV2API.getSiteCateById.replace('{id}', id));
  }
  /**
   * 获取所有站点类型
   * @returns {Observable<MsgResult>|any}
   */
  getAllSiteCate(): Observable<MsgResult> {
    return this.requestUtil.get(SiteV2API.getAllSiteCate);
  }
  /**
   * 删除站点类型
   * @param id :站点类型
   * @returns {Observable<MsgResult>|any}
   */
  deleteSiteCate(id): Observable<MsgResult> {
    return this.requestUtil.delete(SiteV2API.deleteSiteCateById.replace('{id}', id));
  }
  /**
   * 站点类型
   * @param siteCate: 站点类型数据
   * @returns {Observable<MsgResult>|any}
   */
  postSiteCate(siteCate): Observable<MsgResult> {
    const params = this.formUtil.serialize(siteCate);
    return this.requestUtil.post(SiteV2API.postSiteCate, params);
  }
  /**
   * 站点类型
   * @param siteCate: 站点类型数据
   * @returns {Observable<MsgResult>|any}
   */
  updateSiteCate(siteCate): Observable<MsgResult> {
    const params = this.formUtil.serialize(siteCate);
    return this.requestUtil.put(SiteV2API.putSiteCateById.replace('{id}', siteCate.id), params);
  }
}
